﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace SangsTools
{
    [RequireComponent(typeof(RectTransform))]
    public abstract class OnSizeChange : MonoBehaviour
    {
        public RectTransform MyTransform => transform as RectTransform;
        private Vector2 vOldSize;

        private void Awake()
        {
            vOldSize = MyTransform.sizeDelta;
        }

        void Update()
        {
            if (vOldSize != MyTransform.sizeDelta)
            {
                vOldSize = MyTransform.sizeDelta;
                OnUISizeChange(vOldSize);
            }
        }

        protected abstract void OnUISizeChange(Vector2 size);
    }
}